/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jaxb;

import imp.ObjectFactory;
import imp.TEnviNFe;
import java.io.File;
import javax.swing.JOptionPane;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;

/**
 * Manipulador de arquivos XML
 *
 * @author camilo
 */
public class Jaxb {

  public TEnviNFe getXml(String caminho) throws JAXBException {
    TEnviNFe enviNfe = ObjectFactory.createTEnviNFe();
    try {
      JAXBContext context = JAXBContext.newInstance("imp");
      Unmarshaller unmarshaller = context.createUnmarshaller();
      File notaFile = new File(caminho);
      enviNfe = unmarshaller.unmarshal(new StreamSource(notaFile), TEnviNFe.class).getValue();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, "Erro ao iniciar processamento dos dados do xml.\n\n"
              + e.getMessage());
    }
    return enviNfe;
  }
}